package com.hyh.toyshopping.mapper;

import com.hyh.toyshopping.model.User;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * @version 1.0
 * @BelongsProject:IntelliJ IDEA
 * @BelongsPackage:com.hyh.myshopping.mapper
 * @Author:hyhWTX
 * @ClassName:UserMapper
 * @CreateTime:2022年-12月-06日 19:38
 * @Description: TODO (一句话描述以下该类的功能)
 */
@Repository
public interface UserMapper {
    /***
     * @Description:根据用户名获得用户对象
     * @param username
     */
    @Select("select * from tbl_user where user_name = #{username}")
    User getUserByName(String username);
    /***
     * @Description: 用户注册功能
     * @param user
     */

    @Insert("insert into tbl_user values(null,#{user_name},#{user_password},#{user_email},#{user_birthday},#{user_hobbys},#{user_sex},#{user_address},default)")

    void addUser(User user);

    @Select("select user_id,user_name,user_email,user_birthday,user_hobbys,user_sex,user_address,user_status from tbl_user")
    List<User> getUserList();

    @Update("update tbl_user set user_status=#{user_status} where user_id=#{user_id}")
    void updateStatus(@Param("user_id") int user_id, @Param("user_status") int user_status);
    /***
     * @Description: 根据用户名修改密码
     * @param username
     */
    @Update("update tbl_user set user_password =#{user_password} where user_name =#{user_name} ")
    void changePasswordByUserName(@Param("user_name") String username,@Param("user_password") String userpassword);
}
